package com.yzsj.socket.util;

import java.util.HashMap;
import java.util.Map;

public class ResponseBean extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    /**
     * HTTP状态码
     */
    private Integer resultCode;

    /**
     * 返回信息
     */
    private String resultMsg;

    /**
     * 返回的数据
     */
    private Object data;

    public Integer getResultCode() {
        return resultCode;
    }

    public void setResultCode(Integer resultCode) {
        this.resultCode = resultCode;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    public ResponseBean(int resultCode, String resultMsg, Object data) {
        put("resultCode", resultCode);
        put("resultMsg", resultMsg);
        if (data != null) {
            put("data", data);
        }
    }


    /**
     * @return
     * @Description //ResponseBean 两个参数的构造方法
     * @Param resultCode
     * @Param resultMsg
     * @UpdateUser
     * @UpdateDate
     * @Author xsf
     * @Date 2019-04-29 17:51
     **/
    public ResponseBean(int resultCode, String resultMsg) {
        put("resultCode", resultCode);
        put("resultMsg", resultMsg);
    }

    public ResponseBean() {
        put("resultCode", 200);
        put("resultMsg", "操作成功");
    }

    public static ResponseBean error() {
        return error(500, "操作失败");
    }

    public static ResponseBean error(String msg) {
        return error(500, msg);
    }

    public static ResponseBean error(int code, String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("resultCode", code);
        responseBean.put("resultMsg", msg);
        return responseBean;
    }

    public static ResponseBean ok(String msg) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("resultMsg", msg);
        return responseBean;
    }

    public static ResponseBean ok(Map<String, Object> map) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.putAll(map);
        return responseBean;
    }

    public static ResponseBean ok() {
        return new ResponseBean();
    }

    public static ResponseBean success(Object data) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("data", data);
        return responseBean;
    }

    public static ResponseBean success(Object data, int total) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("rows", data);
        responseBean.put("total", total);
        return responseBean;
    }

    public static ResponseBean success(String msgCode) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("msgCode", msgCode);
        return responseBean;
    }

    public static ResponseBean success(String msgCode, Object data) {
        ResponseBean responseBean = new ResponseBean();
        responseBean.put("msgCode", msgCode);
        responseBean.put("data", data);
        return responseBean;
    }

    @Override
    public ResponseBean put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
